﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace Client
{
    class NetClient
    {
        static void Main(string[] args)
        {

            Console.WriteLine("THIS IS THE CLIENT");
            TcpClient tcpclnt = new TcpClient();
            Console.WriteLine("Connecting.....");

            tcpclnt.Connect("127.0.0.1", 8001);
            // use the ipaddress as in the server program


            Console.WriteLine("Connected");
            Console.WriteLine("Sending new board");

            Stream stm = tcpclnt.GetStream();


            byte[] ba = CreateBoard();
            for (int i = 0; i < ba.Length; i++)
            {
                Console.WriteLine(ba[i]);
            }
            Console.WriteLine("Transmitting.....");

            stm.Write(ba, 0, ba.Length);

            byte[] bb = new byte[100];
            int k = stm.Read(bb, 0, 100);

            int index = 0;
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    Console.Write(bb[index] + " ");
                    index++;
                }
                Console.WriteLine();
            }

            Console.ReadKey();

            tcpclnt.Close();
        }

        private static byte[] CreateBoard()
        {
            byte[] board = new byte[64];
            int index = 0;
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    board[index] += 20;
                    index++;
                }
            }
            return board;
        }


    }
}

